using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace vXCopy
{
	public partial class NotifyIconGraph : Component
	{
		// System.Drawing objects that will be used for drawing:
		private Bitmap vxBitmap;
		
		private Graphics g;
		//private Bitmap bitmap;
		private Icon icon;
        // Size of the icon: 16x16
        private const int size = 32;

		public NotifyIconGraph()
		{
			InitializeComponent();

            Bitmap b = new Bitmap(size, size, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

			vxBitmap = new Bitmap((Image)Properties.Resources.vxCopy);

			b = vxBitmap;

			//bitmap = new Bitmap(size,size);
			g = Graphics.FromImage(b);
			g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

			CreateIcon();
		}
		
		// Properties:


		/// <summary>
		///  Stores a reference to the System.Windows.Forms.NotifyIcon object.
		/// </summary>
		public NotifyIcon NotifyIconObject
		{
			get{return ni;}
			set { ni = value; CreateIcon(); }
		}
		private NotifyIcon ni;
		private Icon formIcon;

		public Icon FormIcon
		{
			get { return formIcon; }
			set { formIcon = value; DrawBG(); }
		}
		/// <summary>
		/// The backround color. Use Color.Transparent if you don't want NotifyIconChart to draw background.
		/// </summary>
		public Color BackgroundColor
		{
			get{return backgroundColor;}
			set{backgroundColor = value; CreateIcon();}
		}
		private Color backgroundColor = Color.Transparent;
		/// <summary>
		/// The chart elements' frame color. Use Color.Transparent if you don't want NotifyIconChart to draw frames.
		/// </summary>
		public Color FrameColor
		{
			get{return frameColor;}
			set{frameColor = value; CreateIcon();}
		}
		private Color frameColor = Color.Transparent;

		/// <summary>
		/// This color will be used to draw the first bar or the pie.
		/// </summary>
		public Color Color1
		{
			get{return color;}
			set{color = value; CreateIcon();}
		}
		private Color color = Color.Brown;

		/// <summary>
		/// The value of the first bar or the pie (0-100).
		/// </summary>
		public int Value
		{
			get{return value1;}
			set{value1 = value; CreateIcon();}
		}

		private int value1 = 0;
	
	

		private void CreateIcon()
		{
			DrawPie(value1);
		}

		// Draw pie chart
		private void DrawPie(int pie1)
		{
			// Draw background
			DrawBG();
			// Set GDI+ objects
			Pen p = new Pen(frameColor, 1);
			SolidBrush b = new SolidBrush(color);
			SolidBrush bt = new SolidBrush(Color.Green);

			Font font = new Font("Verdana", 7.0f,FontStyle.Bold);
			
			// Draw pie
			g.FillPie(b, 0, 0, size - 1, size - 1, 270, (int)(pie1 * 3.6));
			g.DrawPie(p, 0, 0, size - 1, size - 1, 270, (int)(pie1 * 3.6));
			
			g.DrawString("vX", font, Brushes.LightGray, 1, 3);
			g.DrawString("vX", font, Brushes.Gray, 0, 2);

			// Create and display icon
			ShowIcon();
		}

		private void DrawBG()
		{
			// Clear Graphics object
			g.Clear(Color.WhiteSmoke );
			//if (ni != null)
			//	ni.Icon = icon;

			//SolidBrush b = new SolidBrush(backgroundColor);
			//g.FillRectangle(b, 0, 0, size, size);
		}

		public void ShowIcon()
		{
			// Convert bitmap to an icon
			icon = Icon.FromHandle(vxBitmap.GetHicon());
			// if none NotifyIcon object was selected, do not draw icon.
			if (ni != null)
				ni.Icon = icon;
			
		}
	}
}
